package cn.hl.hm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hl.hm.dao.DriverLatitudeLongitudeMapper;
import cn.hl.hm.entity.DriverLatitudeLongitude;
import cn.hl.hm.service.DriverLatitudeLongitudeService;
import cn.hl.hm.util.Tools;
@Service
public class DriverLatitudeLongitudeServiceImpl implements DriverLatitudeLongitudeService {

	@Autowired
	DriverLatitudeLongitudeMapper dllMapper;
	@Override
	public List<DriverLatitudeLongitude> selectDriverLatitudeLongitude(DriverLatitudeLongitude dll) {
		// TODO Auto-generated method stub
		return dllMapper.selectDriverLatitudeLongitude(dll);
	}

	@Override
	public int addDriverLatitudeLongitude(DriverLatitudeLongitude dll) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateDriverLatitudeLongitude(DriverLatitudeLongitude dll) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int operDriverLatitudeLongitude(DriverLatitudeLongitude dll) {
		int i=0;
		if(null == dll  ){
			return i;
		}
	 
		Integer driverId_orderId = 0;
		DriverLatitudeLongitude  tlle=null;
		 
		if(null == driverId_orderId || ("null".equals(driverId_orderId)) || Tools.isEmpty(dll.getLat().toString()) || Tools.isEmpty(dll.getLng().toString())){
			return i;
		}
		if(dll.getDriverId() != null   && !("null".equals(driverId_orderId))){
			DriverLatitudeLongitude d = new DriverLatitudeLongitude();
			d.setDriverId(dll.getDriverId());
			List<DriverLatitudeLongitude> ddList=dllMapper.selectDriverLatitudeLongitude(d);
			if(ddList!=null && ddList.size()>0){
				DriverLatitudeLongitude ddd = ddList.get(0);
				//更新
				ddd.setDriverId(dll.getDriverId());
				ddd.setLat(dll.getLat());
				ddd.setLng(dll.getLng());
				ddd.setUpdateTime(new Date());
				i=dllMapper.updateByPrimaryKeySelective(ddd);
		 
			}else{
				//插入
				tlle=new DriverLatitudeLongitude();
				tlle.setDriverId(dll.getDriverId());
				tlle.setLat(dll.getLat());
				tlle.setLng(dll.getLng());
				tlle.setUpdateTime(new Date());
				i=dllMapper.insertSelective(tlle);
			}
		}
		
		return i;
	}

}
